/************************************
*  Copyright (C) 2010 Julien MOTTIN.
*  Contact: julien.mottin@gueydan.eu
*
*  This file is part of Gueydan.
*
*  Gueydan is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  Gueydan is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with Gueydan.  If not, see <http://www.gnu.org/licenses/>.
*
*************************************/
#ifndef VOLUME_H
#define VOLUME_H

// Volume coeffs constants
const static double VolCoeffLiter      = 1.0;
const static double VolCoeffMilliliter = 0.001;
const static double VolCoeffTeaspoon   = 0.00492892159;
const static double VolCoeffTablespoon = 0.014786765;
const static double VolCoeffGallon     = 3.78541178;
const static double VolCoeffCup        = 0.236588236;
const static double VolCoeffPint       = 0.473176473;
const static double VolCoeffOunce      = 0.0295735296;
const static double VolCoeffQuart      = 0.946352946;

// Handled units
enum VolumeUnit
{
    Liter = 0,
    Milliliter,
    Teaspoon,
    Tablespoon,
    Gallon,
    Cup,
    Pint,
    Quart,
    LiquidOunce
};

class QString;

class Volume
{
public:

    // Standard POD class
    Volume(const double iVolume = 0.0, const VolumeUnit iUnit=Liter);
    Volume(const Volume &iV);
    Volume & operator=(const Volume &iV);
    ~Volume();

    // Operators
    bool operator==(const Volume &iV) const;
    bool operator!=(const Volume &iV) const;
    const Volume operator+(const Volume &iV) const;
    const Volume operator-(const Volume &iV) const;
    bool operator<(const Volume &iV) const;
    bool operator<=(const Volume &iV) const;
    bool operator>(const Volume &iV) const;
    bool operator>=(const Volume &iV) const;

    // Converter
    double Value(const VolumeUnit iUnit=Liter) const;
    void FromString(const QString &iString, bool *OK=0);

private:

    double Compare(const Volume &iV) const;

    // Internal data
    double _Value; // in Liter
};

#endif // VOLUME_H
